#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
//#include<stdlib.h>

char *newnew = (char*)"myVAL=66666";

int main()
{
    printf("我的程序要运行了！\n");

    //程序替换
    //execl("/usr/bin/ls", "ls", "-a", "-l", NULL);
    if(fork() == 0)
    {
        printf("I am Child, My Pid Is: %d\n", getpid());
        sleep(1);
        
        char *const argv[] = {
            (char*const)"other",
            (char*const)"-a",
            (char*const)"-b",
            (char*const)"-c",
            (char*const)"-d",
             NULL
             };
        char *const env[] = {
            (char *const)"MYVAL=1223456789",
            NULL
        };
        putenv((char*)newnew);
        //child
        //execl("/usr/bin/ls", "ls", "-a", "-l", NULL);
        //execl("./other", "other", NULL);
        //execlp("ls", "ls", "-l", NULL);
        //execvp("./other", argv);
        //execvp("./other", argv);
        extern char** environ;
        //execvpe("./other", argv, environ);
        exit(1);
    }

    waitpid(-1, NULL, 0);
    printf("我的程序已结束！\n");

    return 0;
}
